/**
 * Created with IDEA
 * author:ju bai
 * Date:2021/7/9
 * Time:17:06
 **/
public class ShellSort {

    /**
     * 希尔排序
     * 时间复杂度：O(1.5) O(n^2)
     * 空间复杂度：O(1)
     * 稳定性：不稳定
     */

    public static void shellSort(int[] array) {
        int[] drr = {5, 3, 1};//增量数组

        for (int i = 0; i < drr.length; i++) {
            shell(array, drr[i]);
        }
    }

    public static void shell(int[] array, int gap) {
        for (int i = gap; i < array.length; i++) {
            int tmp = array[i];
            int j = i - gap;
            for (; j >= 0; j -= gap) {
                if (array[j] > tmp) {
                    array[j + gap] = array[j];
                } else {
                    break;
                }
            }
            array[j + gap] = tmp;
        }
    }
}
